<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of this.list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" />
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
      <!-- 左右按钮
      <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
      下方滚动条
      <div class="swiper-scrollbar"   slot="scrollbar"></div> -->
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        /* 设置图片分页切换按钮 */
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped="scoped">
  /* 通过 >>> 进行样式穿透: 相当于修改了swiper-pagination-bullet-active的全局样式*/
  .wrapper >>> .swiper-pagination-bullet-active
    background: #fff!important
  .wrapper
    width: 100%
    height: 0
    overflow: hidden
    padding-bottom: 31.25% /* 640x200的宽高比 */
    /* 31.25%为图片的高宽比；
    padding-bottom:31.25% 表示设置了wrapper的高度自动撑开为宽度的31.25%的自适应宽高*/
    background: #eee
    .swiper-img
      width: 100%
</style>
